<template>
  <div
    class="todo-item-wrapper"
    @mouseover="item.isHovered = true"
    @mouseleave="item.isHovered = false"
    v-for="(item, index) in props.weatherList"
    :key="item"
  >
    <li class="todo-item">
      <div class="custom-checkbox">
        <h3>{{ item.city }}</h3>
        <span>{{ item.temperature }}度</span>
      </div>
    </li>
    <div
      class="todo-actions"
      :style="{ display: item.isHovered ? 'flex' : 'none' }"
    >
      <button @click="handlelook(item)">查看</button>
      <button @click="handleDelete(index)">删除</button>
    </div>
  </div>
</template>

<script setup>
import router from '@/router';
import { defineProps, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
const isHovered = ref(false)
const props = defineProps({
  weatherList: {
    type: Object,
    required: true,
  },
})
console.log(props.weatherList)

const emit = defineEmits(['del'])
const handlelook = (item) => {
  router.push({ 
    path: `/weather`, 
    query: { city: item.city, value: item.value ,from:'item'} 
  });
}
const handleDelete = (index) => {
  emit('del', index);
}
</script>

<style leng="scss" scoped>
.todo-item-wrapper {
  display: flex;
  align-items: center;
  .todo-item {
    max-height: 300px;
    margin: 10px 0;
    width: 100%;
    justify-content: space-between;
    display: flex;
    color: white;
    overflow: hidden;
    transition: width 0.3s ease;
    /* 添加平滑的过渡效果 */
    &:hover {
      width: 90%;
      transform-origin: left;
    }
    .custom-checkbox {
      background-color: rgb(0 78 113);
      transition-duration: 0.3s;
      padding-left: 1rem;
      padding-right: 1rem;
      padding-top: 0.5rem;
      padding-bottom: 0.5rem;
      justify-content: space-between;
      cursor: pointer;
      width: 100%;
      display: flex;
      h3 {
        margin: 0;
        font-size: inherit;
        font-weight: inherit;
      }
    }
  }
  .todo-actions {
    display: flex;
    gap: 10px;
    button {
      background: rgb(234 179 8);
      width: 100px;
      height: 40px;
      cursor: pointer;
      text-transform: none;
      text-align: center;
      border: none;
      color: white;
    }
  }
}
</style>
